package com.swpu.project.model.entity;

import com.swpu.project.constant.XlxsConstant;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;

import java.util.ArrayList;
import java.util.List;

@Data
@AllArgsConstructor
@NoArgsConstructor
public class InformClassify {

    private String name;
    private List<String> colums;
    private List<String> data = new ArrayList<>();
    private Class<?> entityClass;

    public InformClassify(String name) {

        this.name = name;
    }

    public int getSize() {
        return colums.size();

    }

    public InformClassify(String name, List<String> colums) {
        this.name = name;
        this.colums = colums;
    }

    public void setNameAndClass(String name) {
        this.name = name;
        switch (name) {
            case XlxsConstant.INFORM_HEAVY:
                this.setEntityClass(XlxsConstant.HEAVY_DB_CLASS);

                break;

            case XlxsConstant.INFORM_NON_HEAVY:
                this.setEntityClass(XlxsConstant.NONHEAVY_DB_CLASS);
                break;

            case XlxsConstant.INFORM_MINERAL:
                this.setEntityClass(XlxsConstant.MINERAL_DB_CLASS);
                break;


        }


    }

    void initData(List<Inform> informs) {
        for (int i = 0; i < colums.size(); i++) {
            data.add(i, "0");
            for (int j = 0; j < informs.size(); j++) {
                Inform inform = informs.get(j);
                if (inform.getName().equals(colums.get(i))) {
                    data.set(i, inform.getData());
                    break;
                }
            }


        }


    }


    public Object initEntity() {
        Class<?> entityClass = this.getEntityClass();
        try {
            Object o = entityClass.newInstance();




            return o;
        } catch (Exception e) {
            e.printStackTrace();
          return null;
        }

    }
}
